package org.example.dao;

import org.apache.ibatis.annotations.*;
import org.example.domain.Course;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Jimmy
 * @version 1.0
 */
public interface CourseDao {

    /**
     * 分页查询
     * @param course course
     * @return list
     */
    @Select("<script> select id courseId,name courseName,state,remark courseRemark from st_course " +
            "where 1=1 " +
            "<if test= 'courseId != null '> and id like concat(concat('%',#{courseId}),'%') </if>" +
            "<if test= 'courseName != null '> and name like concat(concat('%',#{courseName}),'%') </if>" +
            "<if test= 'courseRemark != null '> and remark = concat(concat('%',#{courseRemark}),'%') </if>" +
            "</script>")
    @ResultType(Course.class)
    List<Course> findByPage(Course course);

    /**
     * 查询总条目数
     * @param course course
     * @return int
     */
    @Select("<script> select count(*) from st_course " +
            "where 1=1 " +
            "<if test= 'courseId != null '> and id like concat(concat('%',#{courseId}),'%') </if>" +
            "<if test= 'courseName != null '> and name like concat(concat('%',#{courseName}),'%') </if>" +
            "<if test= 'courseRemark != null '> and remark = concat(concat('%',#{courseRemark}),'%') </if>" +
            "</script>")
    int findTotal(Course course);

    /**
     * 根据id查询学科信息
     * @param courseId 学科id
     * @return course
     */
    @Select("select id courseId,name courseName,state,remark courseRemark from st_course where id=#{courseId}")
    Course findById(String courseId);

    /**
     * 添加学科信息
     * @param course course
     * @return int
     */
    @Insert("insert into st_course(id,name,state,remark) values(#{courseId},#{courseName},#{state},#{courseRemark})")
    int addCourse(Course course);

    /**
     * 修改学科信息
     * @param course course
     * @return int
     */
    @Update("<script>update st_course" +
            "<set>" +
            "  <if test='courseName != null'> name=#{courseName}, </if>" +
            "  <if test='state != null'> state=#{state}, </if>" +
            "  <if test='courseRemark != null'> remark=#{courseRemark}, </if>" +
            "</set>" +
            " where id=#{courseId}" +
            "</script>")
    int update(Course course);

    /**
     * 删除学科信息
     * @param courseId 学科id
     * @return int
     */
    @Delete("delete from st_course where id=#{courseId}")
    int delete(String courseId);


}
